<template>
  <div slot>
    <v-card>
      <v-card-title primary-title>
        <div style="width: 100%">
          <h3 class="headline mb-0">填写供应商资料</h3>
          <div>
            <v-form v-model="valid"  >
              <v-text-field
                v-model="name"
                :rules="nameRules"
                label="公司名称"
                required
              ></v-text-field>
              <v-text-field
                v-model="mobile"
                :rules="mobileRules"
                label="联系电话"
                required
              ></v-text-field>
            <v-layout row wrap>
                <v-flex xs12>
                  <v-label>上传营业执照：</v-label>
                  <input type="file" id="yyzz"  accept="image/png,image/gif"  @change="getFile($event)">
                </v-flex>
                <v-flex xs12>
                  <v-label>产品检验合格证书：</v-label>
                  <input type="file" id="ca"  accept="image/png,image/gif" @change="getFile1($event)">
                </v-flex>
                <v-flex xs12>
                  <v-label>其它证照：</v-label>
                  <input type="file" id="outherPic"  accept="image/png,image/gif" @change="getFile2($event)">
                </v-flex>
              </v-layout>
              <v-btn color="success"  @click="submitForm($event)">提交</v-btn>
            </v-form>
          </div>
        </div>
      </v-card-title>
    </v-card>
  </div>
</template>

<script>
  export default {
    name: "CompanyAdd",
    data: () => ({
      valid: false,
      name: '',
      nameRules: [
        v => !!v || '请填写公司名称',
      ],
      mobile: '',
      fullWidth:true,
      mobileRules: [
        v => !!v || '请填写联系电话',
      ],
     yyzz:'',//营业执照
      ca:'',
      outherPic:''

    }),
    methods:{
      getFile(event) {
        this.yyzz = event.target.files[0];
        console.log(this.yyzz);

      },
      getFile1(event) {
        this.ca = event.target.files[0];
        console.log(this.ca);
        },
      getFile2(event) {
        this.outherPic = event.target.files[0];
        console.log(this.outherPic);
      },
      submitForm(event) {
        event.preventDefault();
        let formData = new FormData();
        formData.append('company_name', this.name);
        formData.append('mobile', this.mobile);
        formData.append('yyzz', this.yyzz);
        formData.append('ca', this.ca);
        formData.append('otherPic', this.outherPic);
      /*  formData.append('yyzz', this.file);
        formData.append('yyzz', this.file);*/

        let config = {
          headers: {
            'Content-Type': 'multipart/form-data'
          }
        }
        let this_ = this
        this.axios.post('/index/Company/add', formData, config).then(function (res) {
          if (res.status === 200) {
            /*这里做处理*/
            if (res.data.errno==0){
              this_.$router.push('/company/show')
              alert("保存成功")
            } else{
              alert(res.data.msg)
            }
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
